package activity;

import constants.MessageType;
import interfaces.Observer;
import flyingpig.com.R;
import view.GameView;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.EditText;
import application.Globalstate;

public class GameActivity extends Activity implements Observer{

	private static final String TAG = GameActivity.class.getSimpleName();
	private GameView session;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		session = new GameView(this);
		session.addToObservers(this);
		setContentView(session);
		Log.d(TAG, "GameActivity created, GameView added");
	}

	@Override
	public void onBackPressed() {
		session.checkCurrentScore();
		((ViewGroup) session.getParent()).removeView(session);
		setContentView(R.layout.main);
		final Globalstate gs = (Globalstate) getApplication();
		gs.addHighscore(session.getHighscore());
		Log.d(TAG, "GameView removed, stopping GameActivity");
		finish();
	}

	@Override
	public void objectChanged(MessageType mst, Object o) {
		if (mst == MessageType.BACKPRESSED) {
			session.checkCurrentScore();
			//((ViewGroup) session.getParent()).removeView(session);
			setContentView(R.layout.main);
			final Globalstate gs = (Globalstate) getApplication();
			gs.addHighscore(session.getHighscore());
			Log.d(TAG, "GameView removed, stopping GameActivity");
			finish();
		}
		
	}
	
	
}
